package com.fone.player.entity;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map.Entry;

import android.os.Parcel;
import android.os.Parcelable;

import com.nostra13.universalimageloader.utils.L;

/**
 * 
 * 收藏和缓存实体类
 * 
 * @author wangyang
 * @since 2014年5月13日
 */
public class OfflineCache implements Parcelable {
	/**
	 * 用于传递消息时,数据对应的键
	 */
	public static final String OFFLINE_CACHE = "offline_cache";
	public static final String OFFLINE_CACHE_LIST = "offline_cache_list";
	public static final String OFFLINE_CACHE_IS_PAUSE = "offline_cache_is_pause";
	public static final String OFFLINE_CACHE_FINISH_COUNT = "offline_cache_finish_count";
	public final static String OFFLINE_CACHE_CURRENT_SIZE = "offline_cache_current_size";
	/**
	 * 边播边下
	 */
	public final static int CACHE_STATE_ONLINE = -2;
	/**
	 * 暂停
	 */
	public final static int CACHE_STATE_PAUSE_USER = -1;
	/**
	 * 暂停
	 */
	public final static int CACHE_STATE_PAUSE = 3;
	/**
	 * 等待
	 */
	public final static int CACHE_STATE_WAITING = 0;
	/**
	 * 等待
	 */
	public final static int CACHE_STATE_QWAITING = 6;
	/**
	 * 下载中
	 */
	public final static int CACHE_STATE_DOWNLOADING = 1;
	/**
	 * 操作中
	 */
	public final static int CACHE_STATE_PROCESSING = 99;
	/**
	 * 完成
	 */
	public final static int CACHE_STATE_FINISH = 2;

	/**
	 * 出错
	 */
	public final static int CACHE_STATE_ERROR = 4;

	/**
	 * 未缓存
	 */
	public final static int CACHE_STATE_NOT_DOWNLOAD = 7;
	/**
	 * 所有状态
	 */
	public final static int CACHE_STATE_ALL = 8;
	/**
	 * 全部
	 */
	public final static int CACHE_CONTENT_TYPE_ALL = 0;
	/**
	 * 电影
	 */
	public final static int CACHE_CONTENT_TYPE_MOVIE = 1;
	/**
	 * 电视剧
	 */
	public final static int CACHE_CONTENT_TYPE_TV = 2;
	/**
	 * 动画
	 */
	public final static int CACHE_CONTENT_TYPE_ANIMATION = 3;
	/**
	 * 综艺
	 */
	public final static int CACHE_CONTENT_TYPE_VARIETY = 4;
	/**
	 * 原创
	 */
	public final static int CACHE_CONTENT_TYPE_ORIGINAL = 5;
	/**
	 * 视频直播
	 */
	public final static int CACHE_CONTENT_TYPE_LIVE_VIDEO = 6;
	/**
	 * 音频直播
	 */
	public final static int CACHE_CONTENT_TYPE_LIVE_AUDIO = 7;
	/**
	 * 新闻
	 */
	public final static int CACHE_CONTENT_TYPE_NEWS = 8;
	/**
	 * 短片
	 */
	public final static int CACHE_CONTENT_TYPE_SHORT_FILM = 9;
	/**
	 * 网页
	 */
	public final static int CACHE_CONTENT_TYPE_WEB_PAGE = 10;
	/**
	 * 其他(非剧集类型)
	 */
	public final static int CACHE_CONTENT_TYPE_OTHER = 11;
	/**
	 * 文件
	 */
	public final static int CACHE_HIERARCHY_FILE = 0;
	/**
	 * 文件夹
	 */
	public final static int CACHE_HIERARCHY_FOLDER = 1;
	/**
	 * 文件夹和文件
	 */
	public final static int CACHE_HIERARCHY_ALL = 2;

	/**
	 * 已同步,收藏同步标记
	 */
	public final static int CACHE_FAVOURITE_SYNCHRONZIE_ADD_ALREADY = 0;
	/**
	 * 待同步,收藏同步标记
	 */
	public final static int CACHE_FAVOURITE_SYNCHRONZIE_ADD_WAIT = 1;
	/**
	 * 待删除,收藏同步标记
	 */
	public final static int CACHE_FAVOURITE_SYNCHRONZIE_DELETE_WAIT = 2;

	/**
	 * 获取所有未同步的
	 */
	public final static int CACHE_FAVOURITE_SYNCHRONZIE_ALL_WAIT = 3;
	/**
	 * 获取客户端需要的所有收藏(过滤同步标记是CACHE_FAVOURITE_SYNCHRONZIE_DELETE_WAIT)
	 */
	public final static int CACHE_FAVOURITE_SYNCHRONZIE_CLIENT_ALL = 4;
	/**
	 * 获取服务端需要的所有收藏(查询所有)
	 */
	public final static int CACHE_FAVOURITE_SYNCHRONZIE_SERVER_ALL = 5;
	/**
	 * 标清
	 */
	public final static int CACHE_DEFINITION_STANDARD = 1;
	/**
	 * 高清
	 */
	public final static int CACHE_DEFINITION_HIGH = 2;
	/**
	 * 超清
	 */
	public final static int CACHE_DEFINITION_SUPER = 3;
	/**
	 * 成功
	 */
	public final static int CACHE_ERROR_CODE_SUCCESS = 0;
	/**
	 * 文件不能写入
	 */
	public static final int CACHE_ERROR_CODE_NOT_WRITE = 1;
	/**
	 * 用户操作
	 */
	public static final int CACHE_ERROR_CODE_USER_OPERATE = 2;
	/**
	 * 超时出错
	 */
	public static final int CACHE_ERROR_CODE_TIMEOUT = 3;
	/**
	 * url出错
	 */
	public static final int CACHE_ERROR_CODE_MALFORMED_URL = 4;
	/**
	 * io出错
	 */
	public static final int CACHE_ERROR_CODE_IO = 5;
	/**
	 * 禁止访问
	 */
	public static final int CACHE_ERROR_CODE_CONNECTION_REFUSED = 6;
	/**
	 * 报文解析失败
	 */
	public static final int CACHE_ERROR_CODE_MESSAGE_PARSE_FAIL = 7;
	/**
	 * 报文中分片地址为空
	 */
	public static final int CACHE_ERROR_CODE_FRAGMENT_URL_NULL = 8;
	/**
	 * 请求的分片地址成功后MIME类型错误
	 */
	public static final int CACHE_ERROR_CODE_FRAGMENT_URL_RESPONSE_MIME_FAIL = 9;
	/**
	 * 请求的分片地址后,返回的状态码异常
	 */
	public static final int CACHE_ERROR_CODE_FRAGMENT_URL_RESPONSE_STATUS_CODE_FAIL = 10;

	/**
	 * 在视频详情页添加缓存
	 */
	public final static int CACHE_FROM_PAGE_DETAIL = 1;
	/**
	 * 缓存界面中更多剧集按钮添加缓存
	 */
	public final static int CACHE_FROM_PAGE_MORE = 2;
	/**
	 * 升级(兼容旧数据)
	 */
	public final static int CACHE_FROM_PAGE_UPGRADE = 3;

	// 内容ID(第一层级)
	private long mCacheCID;
	// 内同集合ID(第二层级)
	private long mCacheCCID;
	// 视频ID(收藏是否重复的唯一标识)
	private long mCacheVideoId;
	// 栏目ID(收藏界面请求剧集使用)
	private long mCacheCLID;
	// 节目名称
	private String mCacheName;
	// 节目图片路径
	private String mCacheImageUrl;
	// 节目已经缓存的大小
	private long mCacheAlreadySize;
	// 节目总大小
	private long mCacheTotalSize;
	// 节目缓存状态
	private int mCacheDownloadState = OfflineCache.CACHE_STATE_NOT_DOWNLOAD;
	// 节目内容类型
	private int mCacheContentType;
	// 是否选中下载
	private boolean mCacheIsDownlaod;
	// 是否选中删除
	private boolean mCacheIsDelete;
	// 选集编号
	private String mCacheEpisodeNum;
	// 节目最新片段(更新至1集或1季)
	private String mCacheUpdateEpisodeInfo;
	// 节目层级类型(0可播放的文件,1文件夹)
	private int mCacheHierarchyType;
	// 节目对应详情页地址(第一层级的文件类型点击时使用,小屏播放)
	private String mCacheDetailUrl;
	// 节目地址(第一层级和第二层级点击缓存和全屏播放时使用,pt=1播放,pt=2下载)
	private String mCacheXYZPlayUrl;
	// 剧集地址(第一层级的文件夹类型点击时使用)
	private String mCacheDramaUrl;
	// 记录该条收藏是否和服务器同步,0=已同步 1=待添加至服务器 2=待删除
	private int mCacheSynchronzieType;
	// 节目清晰度(0默认服务器进行选择清晰度,1标清,2高清,3超清)
	private int mCacheDefinitionType;
	// 下载类型(1离线缓存,2图片,3apk,4边播边下)
	private int mCacheDownloadType = 1;
	// 总时长
	private long mCacheDuration;
	// 节目下的碎片数量
	private int mCacheFragmentCount;
	// 缓存本地路径
	private String mCacheStoragePath;
	// 是否可以边下边播
	private boolean mCacheIsPlay;
	// 排序索引(文件层级排序用)
	private int mSortIndex;
	// 错误码
	private int mCacheErrorCode;
	// 错误信息
	private String mCacheErrorMessage;
	// 记录添加收藏记录位置的上报点
	private int mCacheReportPage;
	// 是否是VIP,付费播放时使用
	private boolean mCacheIsVip;
	// 请求重试次数(默认3次)
	private int mRequestNum;
	// 缓存文件夹或文件创建时间
	private long mCacheCreateTime;
	// 添加缓存时的当前界面
	private int mCacheFromPage;
	// 选集集合(用于判断选集是否重复,key是cid)
	private LinkedHashMap<Long, OfflineCache> mOfflineCacheMap = new LinkedHashMap<Long, OfflineCache>();
	// 视频分片集合(只有离线缓存和边播边下时内部使用,其他模块不用关系此集合)
	private LinkedHashMap<String, OfflineCacheFragment> mOfflineCacheFragmentMap = new LinkedHashMap<String, OfflineCacheFragment>();
	// 选集是否可下载
	private boolean mCacheIsDownloadable;
	// 当前视频是否正在详情页播放
	private boolean mCacheIsDetailPlay;
	// 当前层级已经下载完的文件数量(数据库即时统计,不需保存)
	private int mCacheFinishCount;
	// 当前层级所有的文件数量(数据库即时统计,不需保存)
	private int mCacheAllCount;
	// 视频来源,例如:优酷、土豆
	private String mCacheSourceName;

	@Override
	public void writeToParcel(Parcel out, int flags) {
		out.writeLong(mCacheCID);
		out.writeLong(mCacheCCID);
		out.writeLong(mCacheVideoId);
		out.writeLong(mCacheCLID);
		out.writeString(mCacheName);
		out.writeString(mCacheImageUrl);
		out.writeLong(mCacheAlreadySize);
		out.writeLong(mCacheTotalSize);
		out.writeInt(mCacheDownloadState);
		out.writeInt(mCacheContentType);
		out.writeInt(mCacheIsDownlaod ? 1 : 0);
		out.writeInt(mCacheIsDelete ? 1 : 0);
		out.writeString(mCacheEpisodeNum);
		out.writeString(mCacheUpdateEpisodeInfo);
		out.writeInt(mCacheHierarchyType);
		out.writeString(mCacheDetailUrl);
		out.writeString(mCacheXYZPlayUrl);
		out.writeString(mCacheDramaUrl);
		out.writeInt(mCacheSynchronzieType);
		out.writeInt(mCacheDefinitionType);
		out.writeInt(mCacheDownloadType);
		out.writeLong(mCacheDuration);
		out.writeInt(mCacheFragmentCount);
		out.writeString(mCacheStoragePath);
		out.writeInt(mCacheIsPlay ? 1 : 0);
		out.writeInt(mSortIndex);
		out.writeInt(mCacheErrorCode);
		out.writeString(mCacheErrorMessage);
		out.writeInt(mCacheReportPage);
		out.writeLong(mCacheCreateTime);
		out.writeInt(mCacheFromPage);
		out.writeString(mCacheSourceName);
	}

	public static final Parcelable.Creator<OfflineCache> CREATOR = new Parcelable.Creator<OfflineCache>() {
		public OfflineCache createFromParcel(Parcel in) {
			return new OfflineCache(in);
		}

		public OfflineCache[] newArray(int size) {
			return new OfflineCache[size];
		}
	};

	private OfflineCache(Parcel in) {
		mCacheCID = in.readLong();
		mCacheCCID = in.readLong();
		mCacheVideoId = in.readLong();
		mCacheCLID = in.readLong();
		mCacheName = in.readString();
		mCacheImageUrl = in.readString();
		mCacheAlreadySize = in.readLong();
		mCacheTotalSize = in.readLong();
		mCacheDownloadState = in.readInt();
		mCacheContentType = in.readInt();
		mCacheIsDownlaod = in.readInt() == 1;
		mCacheIsDelete = in.readInt() == 1;
		mCacheEpisodeNum = in.readString();
		mCacheUpdateEpisodeInfo = in.readString();
		mCacheHierarchyType = in.readInt();
		mCacheDetailUrl = in.readString();
		mCacheXYZPlayUrl = in.readString();
		mCacheDramaUrl = in.readString();
		mCacheSynchronzieType = in.readInt();
		mCacheDefinitionType = in.readInt();
		mCacheDownloadType = in.readInt();
		mCacheDuration = in.readLong();
		mCacheFragmentCount = in.readInt();
		mCacheStoragePath = in.readString();
		mCacheIsPlay = in.readInt() == 1;
		mSortIndex = in.readInt();
		mCacheErrorCode = in.readInt();
		mCacheErrorMessage = in.readString();
		mCacheReportPage = in.readInt();
		mCacheCreateTime = in.readLong();
		mCacheFromPage = in.readInt();
		mCacheSourceName = in.readString();
	}

	public String getCacheSourceName() {
		return mCacheSourceName;
	}

	public void setCacheSourceName(String cacheSource) {

		mCacheSourceName = cacheSource;
	}

	/**
	 * 
	 * 获取文件夹内已经下载完成的文件数量
	 * 
	 * @return 已经完成的文件数量
	 */
	public int getCacheFinishCount() {
		return mCacheFinishCount;
	}

	public void setCacheFinishCount(int cacheFinishCount) {

		mCacheFinishCount = cacheFinishCount;
	}

	/**
	 * 
	 * 获取文件夹内全部的文件数量
	 * 
	 * @return 全部的文件数量
	 */
	public int getCacheAllCount() {
		return mCacheAllCount;
	}

	public void setCacheAllCount(int cacheAllCount) {

		mCacheAllCount = cacheAllCount;
	}

	public boolean getCacheIsDetailPlay() {
		return mCacheIsDetailPlay;
	}

	public void setCacheIsDetailPlay(boolean cacheIsDetailPlay) {

		mCacheIsDetailPlay = cacheIsDetailPlay;
	}

	public int getCacheFromPage() {
		return mCacheFromPage;
	}

	/**
	 * 
	 * 添加缓存时,是由哪个界面请求的下载
	 * 
	 * @param cacheFromPage
	 *            来自那个界面<br>
	 *            OfflineCache.CACHE_FROM_PAGE_DETAIL 在视频详情页添加缓存<br>
	 *            OfflineCache.CACHE_FROM_PAGE_MORE 缓存界面中更多剧集按钮添加缓存
	 * @return void
	 */
	public void setCacheFromPage(int cacheFromPage) {

		mCacheFromPage = cacheFromPage;
	}

	public long getCacheCreateTime() {
		return mCacheCreateTime;
	}

	public void setCacheCreateTime(long cacheCreateTime) {

		mCacheCreateTime = cacheCreateTime;
	}

	public boolean getCacheIsVip() {
		return mCacheIsVip;
	}

	public void setCacheIsVip(boolean cacheIsVip) {

		mCacheIsVip = cacheIsVip;
	}

	public int getCacheReportPage() {
		return mCacheReportPage;
	}

	public void setCacheReportPage(int cacheReportPage) {

		mCacheReportPage = cacheReportPage;
	}

	public int getCacheErrorCode() {
		return mCacheErrorCode;
	}

	public void setCacheErrorCode(int cacheErrorCode) {

		mCacheErrorCode = cacheErrorCode;
	}

	public String getCacheErrorMessage() {
		return mCacheErrorMessage;
	}

	public void setCacheErrorMessage(String cacheErrorMessage) {

		mCacheErrorMessage = cacheErrorMessage;
	}

	public int getSortIndex() {
		return mSortIndex;
	}

	public void setSortIndex(int sortIndex) {

		mSortIndex = sortIndex;
	}

	/**
	 * 
	 * 获取url数组
	 * 
	 * @return String[]
	 */
	public String[] getOfflineCacheFragmentUrlArray() {
		String[] urlArray = new String[mOfflineCacheFragmentMap.size()];
		Iterator<Entry<String, OfflineCacheFragment>> iterator = mOfflineCacheFragmentMap
				.entrySet().iterator();
		int i = 0;
		while (iterator.hasNext()) {
			Entry<String, OfflineCacheFragment> entry = (Entry<String, OfflineCacheFragment>) iterator
					.next();
			OfflineCacheFragment offlineCacheFragment = entry.getValue();
			if (offlineCacheFragment != null) {
				String storagePath = offlineCacheFragment
						.getCacheFragmentStoragePath();

				urlArray[i] = storagePath;

				i++;
			}

		}

		return urlArray;
	}

	/**
	 * 
	 * 获取时长数组
	 * 
	 * @return String[]
	 */
	public int[] getOfflineCacheFragmentDurationArray() {
		int[] durationArray = new int[mOfflineCacheFragmentMap.size()];
		Iterator<Entry<String, OfflineCacheFragment>> iterator = mOfflineCacheFragmentMap
				.entrySet().iterator();
		int i = 0;
		while (iterator.hasNext()) {
			Entry<String, OfflineCacheFragment> entry = (Entry<String, OfflineCacheFragment>) iterator
					.next();
			OfflineCacheFragment offlineCacheFragment = entry.getValue();
			if (offlineCacheFragment != null) {
				durationArray[i] = (int) offlineCacheFragment
						.getCacheDuration();
			} else {
				L.w("OfflineCache", "getOfflineCacheFragmentDurationArray",
						"offlineCacheFragment=null");
			}
			i++;
		}

		return durationArray;
	}

	public List<OfflineCacheFragment> getOfflineCacheFragmentList() {
		List<OfflineCacheFragment> offlineCacheFragmentList = new ArrayList<OfflineCacheFragment>();
		offlineCacheFragmentList.addAll(mOfflineCacheFragmentMap.values());
		return offlineCacheFragmentList;
	}

	public LinkedList<OfflineCacheFragment> getOfflineCacheFragmentLinkedList() {
		LinkedList<OfflineCacheFragment> offlineCacheFragmentList = new LinkedList<OfflineCacheFragment>();
		offlineCacheFragmentList.addAll(mOfflineCacheFragmentMap.values());
		return offlineCacheFragmentList;
	}

	public void setOfflineCacheFragmentList(
			List<OfflineCacheFragment> offlineCacheFragmentList) {
		for (OfflineCacheFragment offlineCacheFragment : offlineCacheFragmentList) {
			mOfflineCacheFragmentMap.put(
					offlineCacheFragment.getCacheFragmentUrl(),
					offlineCacheFragment);
		}

	}

	public void addOfflineCacheFragment(
			OfflineCacheFragment offlineCacheFragment) {
		mOfflineCacheFragmentMap.put(
				offlineCacheFragment.getCacheFragmentUrl(),
				offlineCacheFragment);
	}

	/**
	 * 
	 * 清空
	 * 
	 * @return void
	 */
	public void clearOfflineCacheFragmentList() {
		mOfflineCacheFragmentMap.clear();
	}

	public boolean getCacheIsPlay() {
		int num = 0;
		if (mCacheTotalSize > 0) {
			num = (int) (((float) mCacheAlreadySize / (float) mCacheTotalSize) * 100);
		}
		mCacheIsPlay = num >= 15;
		return mCacheIsPlay;
	}

	public void setCacheIsPlay(boolean cacheIsPlay) {

		mCacheIsPlay = cacheIsPlay;
	}

	public int getCacheDefinitionType() {
		return mCacheDefinitionType;
	}

	public void setCacheDefinitionType(int cacheDefinitionType) {

		mCacheDefinitionType = cacheDefinitionType;
	}

	public int getCacheDownloadType() {
		return mCacheDownloadType;
	}

	public void setCacheDownloadType(int cacheDownloadType) {

		mCacheDownloadType = cacheDownloadType;
	}

	/**
	 * 
	 * 获取清晰度
	 * 
	 * 
	 * @return int 清晰度<br>
	 *         OfflineCache.CACHE_DEFINITION_STANDARD 标清<br>
	 *         OfflineCache.CACHE_DEFINITION_HIGH 高清<br>
	 *         OfflineCache.CACHE_DEFINITION_SUPER 超清<br>
	 */
	public long getCacheDuration() {
		return mCacheDuration;
	}

	/**
	 * 
	 * 设置清晰度
	 * 
	 * 
	 * @return int 清晰度<br>
	 *         OfflineCache.CACHE_DEFINITION_STANDARD 标清<br>
	 *         OfflineCache.CACHE_DEFINITION_HIGH 高清<br>
	 *         OfflineCache.CACHE_DEFINITION_SUPER 超清<br>
	 */
	public void setCacheDuration(long cacheDuration) {

		mCacheDuration = cacheDuration;
	}

	public int getCacheFragmentCount() {
		return mOfflineCacheFragmentMap.size();
	}

	public void setCacheFragmentCount(int cacheFragmentCount) {

		mCacheFragmentCount = cacheFragmentCount;
	}

	public String getCacheStoragePath() {
		return mCacheStoragePath;
	}

	public void setCacheStoragePath(String cacheStoragePath) {

		mCacheStoragePath = cacheStoragePath;
	}

	public long getCacheCID() {
		return mCacheCID;
	}

	public void setCacheCID(long cacheCID) {

		mCacheCID = cacheCID;
	}

	public long getCacheCCID() {
		return mCacheCCID;
	}

	public void setCacheCCID(long cacheCCID) {

		mCacheCCID = cacheCCID;
	}

	public long getCacheVideoId() {
		return mCacheVideoId;
	}

	public void setCacheVideoId(long cacheVideoId) {

		mCacheVideoId = cacheVideoId;
	}

	public long getCacheCLID() {
		return mCacheCLID;
	}

	public void setCacheCLID(long cacheCLID) {

		mCacheCLID = cacheCLID;
	}

	public String getCacheDetailUrl() {
		return mCacheDetailUrl == null ? "" : mCacheDetailUrl;
	}

	public void setCacheDetailUrl(String cacheDetailUrl) {

		mCacheDetailUrl = cacheDetailUrl;
	}

	public String getCacheXYZPlayUrl() {
		return mCacheXYZPlayUrl == null ? "" : mCacheXYZPlayUrl;
	}

	public void setCacheXYZPlayUrl(String cacheXYZPlayUrl) {

		mCacheXYZPlayUrl = cacheXYZPlayUrl;
	}

	public String getCacheDramaUrl() {
		return mCacheDramaUrl == null ? "" : mCacheDramaUrl;
	}

	public void setCacheDramaUrl(String cacheDramaUrl) {

		mCacheDramaUrl = cacheDramaUrl;
	}

	/**
	 * 
	 * 获取收藏同步标记
	 * 
	 * 
	 * @return int 收藏同步标记<br>
	 *         OfflineCache.CACHE_FAVOURITE_SYNCHRONZIE_ADD_ALREADY 已同步<br>
	 *         OfflineCache.CACHE_FAVOURITE_SYNCHRONZIE_ADD_WAIT 待添加<br>
	 *         OfflineCache.CACHE_FAVOURITE_SYNCHRONZIE_DELETE_WAIT 待删除<br>
	 */
	public int getCacheSynchronzieType() {
		return mCacheSynchronzieType;
	}

	/**
	 * 
	 * 设置收藏同步标记
	 * 
	 * 
	 * @return int 收藏同步标记<br>
	 *         OfflineCache.CACHE_FAVOURITE_SYNCHRONZIE_ADD_ALREADY 已同步<br>
	 *         OfflineCache.CACHE_FAVOURITE_SYNCHRONZIE_ADD_WAIT 待添加<br>
	 *         OfflineCache.CACHE_FAVOURITE_SYNCHRONZIE_DELETE_WAIT 待删除<br>
	 */
	public void setCacheSynchronzieType(int cacheSynchronzieType) {

		mCacheSynchronzieType = cacheSynchronzieType;
	}

	public ArrayList<OfflineCache> getOfflineCacheList() {
		ArrayList<OfflineCache> offlineCacheList = new ArrayList<OfflineCache>(
				mOfflineCacheMap.values());
		return offlineCacheList;
	}

	public void addOfflineCacheFile(OfflineCache offlineCache) {
		// mCacheAlreadySize += offlineCache.getCacheAlreadySize();
		// mCacheTotalSize += offlineCache.getCacheTotalSize();
		mOfflineCacheMap.put(offlineCache.getCacheCID(), offlineCache);
	}

	public void setOfflineCacheFile(OfflineCache offlineCache) {
		mOfflineCacheMap.put(offlineCache.getCacheCID(), offlineCache);
	}

	/**
	 * 
	 * 判断缓存文件是否重复
	 * 
	 * @param offlineCache
	 * @return boolean 是否重复
	 */
	public boolean containsCID(OfflineCache offlineCache) {
		return mOfflineCacheMap.containsKey(offlineCache.getCacheCID());
	}

	/**
	 * 
	 * 根据CID获取离线缓存对象
	 * 
	 * @param cid
	 * @return OfflineCache 离线缓存对象
	 */
	public OfflineCache getOfflineCacheByCID(long cid) {
		OfflineCache offlineCache = mOfflineCacheMap.get(cid);
		if (offlineCache != null) {
			return offlineCache;
		}
		return null;
	}

	/**
	 * 
	 * 根据cid删除缓存对象
	 * 
	 * @param cid
	 *            内容ID
	 * @return void
	 */
	public void deleteOfflineCacheByCID(long cid) {

		// 删除内存数据
		mOfflineCacheMap.remove(cid);

	}

	public void setOfflineCacheListChange(List<OfflineCache> offlineCacheList) {
		// 判断唯一性使用
		for (OfflineCache offlineCache : offlineCacheList) {
			if (mOfflineCacheMap.containsKey(offlineCache.getCacheCID())) {
				OfflineCache offlineCacheFileTemp = mOfflineCacheMap
						.get(offlineCache.getCacheCID());
				offlineCacheFileTemp.setCacheAlreadySize(offlineCache
						.getCacheAlreadySize());
				offlineCacheFileTemp.setCacheTotalSize(offlineCache
						.getCacheTotalSize());
				offlineCacheFileTemp.setCacheDownloadState(offlineCache
						.getCacheDownloadState());
				mOfflineCacheMap.put(offlineCache.getCacheCID(),
						offlineCacheFileTemp);
			}

		}
	}

	public void setOfflineCacheList(List<OfflineCache> offlineCacheList) {
		// 判断唯一性使用
		for (OfflineCache offlineCache : offlineCacheList) {
			mOfflineCacheMap.put(offlineCache.getCacheCID(), offlineCache);

		}
	}

	/**
	 * 
	 * 获取节目层级类型
	 * 
	 * 
	 * @return int 节目层级类型<br>
	 *         OfflineCache.CACHE_HIERARCHY_FILE 文件<br>
	 *         OfflineCache.CACHE_HIERARCHY_FOLDER 文件夹<br>
	 */
	public int getCacheHierarchyType() {
		return mCacheHierarchyType;
	}

	/**
	 * 
	 * 设置节目层级类型
	 * 
	 * 
	 * @param cacheHierarchyType
	 *            节目层级类型<br>
	 *            OfflineCache.CACHE_HIERARCHY_FILE 文件<br>
	 *            OfflineCache.CACHE_HIERARCHY_FOLDER 文件夹<br>
	 */
	public void setCacheHierarchyType(int cacheHierarchyType) {

		mCacheHierarchyType = cacheHierarchyType;
	}

	public String getCacheName() {
		return mCacheName == null ? "" : mCacheName;
	}

	public void setCacheName(String cacheName) {

		mCacheName = cacheName;
	}

	public String getCacheImageUrl() {
		return mCacheImageUrl == null ? "" : mCacheImageUrl;
	}

	public void setCacheImageUrl(String cacheImageUrl) {

		mCacheImageUrl = cacheImageUrl;
	}

	public String getCacheEpisodeNum() {
		return mCacheEpisodeNum == null ? "" : mCacheEpisodeNum;
	}

	public void setCacheEpisodeNum(String cacheEpisodeNum) {

		mCacheEpisodeNum = cacheEpisodeNum;
	}

	public String getCacheEpisodeUpdateInfo() {
		return mCacheUpdateEpisodeInfo == null ? "" : mCacheUpdateEpisodeInfo;
	}

	public void setCacheEpisodeUpdateInfo(String cacheUpdateEpisodeInfo) {

		mCacheUpdateEpisodeInfo = cacheUpdateEpisodeInfo;
	}

	public long getCacheAlreadySize() {
		return mCacheAlreadySize;
	}

	public void setCacheAlreadySize(long cacheAlreadySize) {
		Iterator<Entry<String, OfflineCacheFragment>> iterator = mOfflineCacheFragmentMap
				.entrySet().iterator();
		while (iterator.hasNext()) {
			Entry<String, OfflineCacheFragment> entry = iterator.next();
			OfflineCacheFragment offlineCacheFragment = entry.getValue();
			offlineCacheFragment.getCacheAlreadySize();
		}
		mCacheAlreadySize = cacheAlreadySize;
	}

	public void addCacheAlreadySize(long cacheAlreadySize) {

		mCacheAlreadySize += cacheAlreadySize;
	}

	public void addCacheTotalSize(long cacheTotalSize) {

		mCacheTotalSize += cacheTotalSize;
	}

	public long getCacheTotalSize() {
		return mCacheTotalSize;
	}

	public void setCacheTotalSize(long cacheTotalSize) {

		mCacheTotalSize = cacheTotalSize;
	}

	/**
	 * 
	 * 获取缓存状态
	 * 
	 * 
	 * @return int 缓存内容类型<br>
	 *         OfflineCache.CACHE_STATE_WAITING 等待<br>
	 *         OfflineCache.CACHE_STATE_PAUSE 暂停<br>
	 *         OfflineCache.CACHE_STATE_DOWNLOADING 下载中<br>
	 *         OfflineCache.CACHE_STATE_FINISH 完成<br>
	 *         OfflineCache.CACHE_STATE_ERROR 出错<br>
	 */
	public int getCacheDownloadState() {
		return mCacheDownloadState;
	}

	/**
	 * 
	 * 设置缓存状态
	 * 
	 * @param cacheState
	 *            缓存状态<br>
	 *            OfflineCache.CACHE_STATE_WAITING 等待<br>
	 *            OfflineCache.CACHE_STATE_PAUSE 暂停<br>
	 *            OfflineCache.CACHE_STATE_DOWNLOADING 下载中<br>
	 *            OfflineCache.CACHE_STATE_FINISH 完成<br>
	 *            OfflineCache.CACHE_STATE_ERROR 出错<br>
	 * @return void
	 */
	public void setCacheDownloadState(int cacheState) {

		mCacheDownloadState = cacheState;
	}

	/**
	 * 
	 * 获取缓存内容类型
	 * 
	 * 
	 * @return int 缓存内容类型<br>
	 *         OfflineCache.CACHE_CONTENT_TYPE_ALL 全部<br>
	 *         OfflineCache.CACHE_CONTENT_TYPE_MOVIE 电影<br>
	 *         OfflineCache.CACHE_CONTENT_TYPE_TV 电视剧<br>
	 *         OfflineCache.CACHE_CONTENT_TYPE_ANIMATION 动漫<br>
	 *         OfflineCache.CACHE_CONTENT_TYPE_VARIETY 综艺<br>
	 *         OfflineCache.CACHE_CONTENT_TYPE_ORIGINAL 原创<br>
	 *         OfflineCache.CACHE_CONTENT_TYPE_LIVE_VIDEO 视频直播<br>
	 *         OfflineCache.CACHE_CONTENT_TYPE_LIVE_AUDIO 音频直播<br>
	 *         OfflineCache.CACHE_CONTENT_TYPE_NEWS 新闻<br>
	 *         OfflineCache.CACHE_CONTENT_TYPE_SHORT_FILM 短片<br>
	 *         OfflineCache.CACHE_CONTENT_TYPE_WEB_PAGE 网页<br>
	 */
	public int getCacheContentType() {
		return mCacheContentType;
	}

	/**
	 * 
	 * 设置缓存内容类型
	 * 
	 * @param cacheContentType
	 *            缓存内容类型<br>
	 *            来自服务器的favtyp字段
	 * @return void
	 */
	public void setCacheContentType(int cacheContentType) {

		mCacheContentType = cacheContentType;
	}

	public boolean getCacheIsDownlaod() {
		return mCacheIsDownlaod;
	}

	public void setCacheIsDownlaod(boolean cacheIsDownlaod) {

		mCacheIsDownlaod = cacheIsDownlaod;
	}

	public boolean getCacheIsDelete() {
		return mCacheIsDelete;
	}

	public void setCacheIsDelete(boolean cacheIsDelete) {

		mCacheIsDelete = cacheIsDelete;
	}

	public boolean getCacheIsDownloadable() {
		return mCacheIsDownloadable;
	}

	public void setCacheIsDownloadable(boolean mCacheIsDownloadable) {

		this.mCacheIsDownloadable = mCacheIsDownloadable;
	}

	/**
	 * 
	 * 根据栏目id判断内容类型(兼容旧版本) <br>
	 * 电影 36527 电视剧 36528 综艺 36565 动漫 36566 直播 36567 热点 36530 搞笑 38142 纪录片 38662
	 * 美女 39202 原创 39222 微电影 39223 音乐 39224 美剧 39203 预告片 39225 八卦 39226 体育 39227
	 * 母婴 39228 时尚 39229 排行榜 36531 旅游 41622 生活 39742 热门专题 36568
	 * 
	 * @param clid
	 *            栏目id
	 * @return int 内容类型
	 */
	public int getContentTypeByCLID(long clid) {
		int contentType = 0;
		switch ((int) clid) {
		case 36527:
		case 39223:
			contentType = CACHE_CONTENT_TYPE_MOVIE;
			break;
		case 36528:
		case 39203:
			contentType = CACHE_CONTENT_TYPE_TV;
			break;
		case 36565:
			contentType = CACHE_CONTENT_TYPE_VARIETY;
			break;
		case 36566:
			contentType = CACHE_CONTENT_TYPE_ANIMATION;
			break;
		case 36567:
		case 36530:
		case 38142:
		case 38662:
		case 39202:
		case 39224:
		case 39227:
		case 39228:
		case 39229:
		case 36531:
		case 41622:
		case 39742:
		case 36568:
			contentType = CACHE_CONTENT_TYPE_OTHER;
			break;
		case 39222:
			contentType = CACHE_CONTENT_TYPE_ORIGINAL;
			break;
		case 39225:
		case 39226:
			contentType = CACHE_CONTENT_TYPE_SHORT_FILM;
			break;
		default:
			contentType = CACHE_CONTENT_TYPE_OTHER;
			break;
		}
		return contentType;
	}

	public OfflineCache() {

	}

	@Override
	public int describeContents() {
		return 0;
	}

	@Override
	public String toString() {
		return "OfflineCache [mCacheCID=" + mCacheCID + ", mCacheCCID="
				+ mCacheCCID + ", mCacheVideoId=" + mCacheVideoId
				+ ", mCacheCLID=" + mCacheCLID + ", mCacheName=" + mCacheName
				+ ", mCacheImageUrl=" + mCacheImageUrl + ", mCacheAlreadySize="
				+ mCacheAlreadySize + ", mCacheTotalSize=" + mCacheTotalSize
				+ ", mCacheDownloadState=" + mCacheDownloadState
				+ ", mCacheContentType=" + mCacheContentType
				+ ", mCacheIsDownlaod=" + mCacheIsDownlaod
				+ ", mCacheIsDelete=" + mCacheIsDelete + ", mCacheEpisodeNum="
				+ mCacheEpisodeNum + ", mCacheUpdateEpisodeInfo="
				+ mCacheUpdateEpisodeInfo + ", mCacheHierarchyType="
				+ mCacheHierarchyType + ", mCacheDetailUrl=" + mCacheDetailUrl
				+ ", mCacheXYZPlayUrl=" + mCacheXYZPlayUrl
				+ ", mCacheDramaUrl=" + mCacheDramaUrl
				+ ", mCacheSynchronzieType=" + mCacheSynchronzieType
				+ ", mCacheDefinitionType=" + mCacheDefinitionType
				+ ", mCacheDownloadType=" + mCacheDownloadType
				+ ", mCacheDuration=" + mCacheDuration
				+ ", mCacheFragmentCount=" + mCacheFragmentCount
				+ ", mCacheStoragePath=" + mCacheStoragePath
				+ ", mCacheIsPlay=" + mCacheIsPlay + ", mSortIndex="
				+ mSortIndex + ", mCacheErrorCode=" + mCacheErrorCode
				+ ", mCacheReportPage=" + mCacheReportPage + ", mCacheIsVip="
				+ mCacheIsVip + ", mRequestNum=" + mRequestNum
				+ ", mCacheCreateTime=" + mCacheCreateTime
				+ ", mCacheFromPage=" + mCacheFromPage + ", mOfflineCacheMap="
				+ mOfflineCacheMap + ", mOfflineCacheFragmentList="
				+ mOfflineCacheFragmentMap + ", mCacheIsDownloadable="
				+ mCacheIsDownloadable + "]";
	}

}
